| Ninjadvloot.inc v1.1 
#Event ALCantLoot         "#*#may not loot this corpse#*#" 

Sub SetupAdvLootVars 
/declare ALDontLoot        int    outer 
/declare CorpseRotTimer    timer  outer 
/declare CorpseList        string outer 
/call ALLoadVar Settings LootMobs      TRUE  bool 
/call ALLoadVar Settings CorpseRadius  100   int 
/call ALLoadVar Settings MobsTooClose  50    int 
/call ALLoadVar Settings CorpseRotTime 440s  string 
/call ALLoadVar Settings ReportLoot    FALSE bool 
/call ALLoadVar Settings LootChannel   echo  string 
/if (!${Defined[${AlertList}]}) /declare AlertList int outer 1 
/squelch /alert clear 25 
/return 

Sub ALLoadVar(IniSection,IniVar,IniValue,VarType) 
/if (!${Defined[${IniVar}]} && ${Defined[VarType]}) /declare ${IniVar} ${VarType} outer 
/declare IniString string local ${Ini[${LootINIFile},${IniSection},${IniVar},NOTFOUND]} 
/varset ${IniVar} ${IniString} 
/if (${IniString.Equal["NOTFOUND"]}) { 
  /if (${IniString.Equal["NOTFOUND"]}) /varset ${IniVar} ${IniValue} 
  /ini "${LootINIFile}" "${IniSection}" "${IniVar}" "${${IniVar}}" 
} 
/return 

Sub LootCorpse 
/declare i          int    local 
/declare loottotal  int    local 
/declare LootList   string local 
:ALauto_inv 
/if (${Cursor.ID}) { 
  /if (${Cursor.NoDrop} && !${Me.FreeInventory}) /return 
  /timed 5 /autoinventory 
  /delay 5s !${Cursor.ID} 
  /goto :ALauto_inv 
} 
/loot 
/delay 3s ${Corpse.Open} 
/doevents ALCantLoot 
/if (${Target.ID}==${ALDontLoot} && ${Spawn[${ALDontLoot}].ID}) /squelch /alert add 25 id ${ALDontLoot} 
/if (${Target.ID}!=${ALDontLoot}) /delay 1s 
/if (${Corpse.Open} && ${Corpse.Items}) { 
  /varset loottotal ${Corpse.Items} 
  :ALlootlag 
  /delay 1s ${loottotal}!=${Corpse.Items} 
  /if (${loottotal}!=${Corpse.Items}) { 
    /varset loottotal ${Corpse.Items} 
    /goto :ALlootlag 
  } 
  /for i 1 to ${loottotal} 
  /if (!${Select[${Ini[${LootINIFile},"${Corpse.Item[${i}].Name.Left[1]}","${Corpse.Item[${i}]}"]},Ignore,Keep,Destroy]}) { 
    /if (${Corpse.Item[${i}].NoDrop}) /ini "${LootINIFile}" "${Corpse.Item[${i}].Name.Left[1]}" "${Corpse.Item[${i}]}" Ignore 
    /if (!${Corpse.Item[${i}].NoDrop}) /ini "${LootINIFile}" "${Corpse.Item[${i}].Name.Left[1]}" "${Corpse.Item[${i}]}" Keep 
  } 
  /if (${Ini[${LootINIFile},"${Corpse.Item[${i}].Name.Left[1]}","${Corpse.Item[${i}]}"].NotEqual[Destroy]} && !${Me.FreeInventory} && (!${FindItemCount[=${Corpse.Item[${i}].Name}]} || (${FindItemCount[=${Corpse.Item[${i}].Name}]} && ${Corpse.Item[${i}].Stackable} && ${Math.Calc[20-${Math.Calc[${FindItemCount[=${Corpse.Item[${i}].Name}]}-${Int[${Math.Calc[${FindItemCount[=${Corpse.Item[${i}].Name}]}/20]}]}*20]}]}==20)) || (${Corpse.Item[${i}].Lore} && ${InvSlot[${Corpse.Item[${i}]}]}) || ${Ini[${LootINIFile},"${Corpse.Item[${i}].Name.Left[1]}","${Corpse.Item[${i}]}"].Equal[Ignore]}) /varset LootList ${LootList}${Corpse.Item[${i}]}, 
  /if ((!${Corpse.Item[${i}].Lore} || !${InvSlot[${Corpse.Item[${i}]}]}) && (${Me.FreeInventory} || (${FindItemCount[=${Corpse.Item[${i}].Name}]} && ${Corpse.Item[${i}].Stackable} && ${Math.Calc[20-${Math.Calc[${FindItemCount[=${Corpse.Item[${i}].Name}]}-${Int[${Math.Calc[${FindItemCount[=${Corpse.Item[${i}].Name}]}/20]}]}*20]}<20]})) && ${Ini[${LootINIFile},"${Corpse.Item[${i}].Name.Left[1]}","${Corpse.Item[${i}]}"].Equal[Keep]}) /call LootItem ${i} Keep right 
  /if (${Ini[${LootINIFile},"${Corpse.Item[${i}].Name.Left[1]}","${Corpse.Item[${i}]}"].Equal[Destroy]}) /call LootItem ${i} Destroy left 
  /next i 
  /if (${Corpse.Items}) { 
    /if (${ReportLoot}) /${LootChannel} ${LootList} left on corpse. 
    /if (${Target.ID}) /squelch /alert add 25 id ${Target.ID} 
    /varset CorpseRotTimer ${CorpseRotTime} 
  } 
} 
/nomodkey /notify LootWnd LW_DoneButton leftmouseup 
/delay 5s !${Corpse.Open} 
/return 

Sub LootItem(int i,DoWhat,WhichButton) 
/nomodkey /shift /itemnotify loot${i} ${WhichButton}mouseup 
/if (${Corpse.Item[${i}].NoDrop}) { 
  /delay 1s ${Window[ConfirmationDialogBox].Open} 
} 
/if (${Window[ConfirmationDialogBox].Open}) /nomodkey /notify ConfirmationDialogBox Yes_Button leftmouseup 
/if (${WhichButton.Equal[left]}) /delay 5s ${Cursor.ID} 
/if (${DoWhat.Equal[Keep]}) /timed 5 /autoinventory 
/if (${DoWhat.Equal[Destroy]}) { 
  /destroy 
  /delay 1s ${Window[ConfirmationDialogBox].Open} 
  /if (${Window[ConfirmationDialogBox].Open}) /nomodkey /notify ConfirmationDialogBox Yes_Button leftmouseup 
} 
/delay 5s !${Cursor.ID} && !${Corpse.Item[${i}].ID} 
/return 

Sub LootMobs 
/declare DeadCount int local ${SpawnCount[corpse radius ${CorpseRadius} zradius 100 noalert 25]} 
/declare LiveCount int local ${SpawnCount[npc radius ${MobsTooClose} zradius 100 noalert ${AlertList}]} 
/if (!${LootMobs} || ${LiveCount} || !${DeadCount} || ${Me.Combat} || (${Cursor.NoDrop} && !${Me.FreeInventory})) /return 
/if (!${CorpseRotTimer}) /squelch /alert clear 25 
/declare i int local 
/varset CorpseList | 
/for i 1 to ${DeadCount} 
/varset CorpseList ${CorpseList}${NearestSpawn[${i},corpse radius ${CorpseRadius} noalert 25].ID}| 
/next i 
/if (${Me.Mount.ID}) /dismount 
/for i 1 to ${DeadCount} 
/if (${Spawn[${CorpseList.Arg[${i},|]}].Deity.ID} && ${Spawn[${CorpseList.Arg[${i},|]}].ID}) /squelch /alert add 25 id ${Spawn[${CorpseList.Arg[${i},|]}].Deity.ID} 
/if (!${Spawn[${CorpseList.Arg[${i},|]}].Deity.ID}) { 
  /if (${Target.ID}!=${Spawn[${CorpseList.Arg[${i},|]}].ID}) /target id ${Spawn[${CorpseList.Arg[${i},|]}].ID} 
  /if (!${Me.Standing}) /stand 
  /delay 2s ${Target.ID}==${Spawn[${CorpseList.Arg[${i},|]}].ID} && ${Me.Standing} 
  /if (${Spawn[${CorpseList.Arg[${i},|]}].Distance}>10) /moveto loc ${Spawn[${CorpseList.Arg[${i},|]}].Y} ${Spawn[${CorpseList.Arg[${i},|]}].X} 
  /delay 10s ${Spawn[${CorpseList.Arg[${i},|]}].Distance}<10 
  /if (${Spawn[${CorpseList.Arg[${i},|]}].Distance}<15) /call LootCorpse 
  /if (${Stick.Status.Equal[ON]}) /squelch /stick off 
} 
/next i 
/return 

Sub Event_ALCantLoot 
/varset ALDontLoot ${Target.ID} 
/return